package com.leetcode;

/**
 * @author fy
 * @date 2022/3/29 15:55
 */
public class Solution406 {

//    public int[][] reconstructQueue(int[][] people) {
//
//    }

    public int lengthOfLastWord(String s) {
        int index = s.length() - 1;
        while (s.charAt(index) == ' ') {
            index--;
        }
        int wordLength = 0;
        while (index >= 0 && s.charAt(index) != ' ') {
            wordLength++;
            index--;
        }
        return wordLength;
    }

    public int lengthOfLastWord1(String s) {
        if (s == null) {
            return 0;
        }
        String[] arr = s.split(" ");
        if (arr[arr.length - 1].equals(" ")) {
            return arr[arr.length - 2].length();
        } else {
            return arr[arr.length - 1].length();
        }
    }
    public static void main(String[] args) {
        System.out.println(new Solution406().lengthOfLastWord(" kfkdks klll ll  "));
    }

}
